<template>
    <div class="app-container">
      <!-- <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        v-show="showSearch"
      >
        <el-form-item label="新闻标题" prop="noticeTitle">
          <el-input
            v-model="queryParams.noticeTitle"
            placeholder="请输入新闻标题"
            clearable
            style="width: 240px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
  
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form> -->
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['company:news:add']"
            >新增</el-button
          >
        </el-col>
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>
  
      <el-table fit v-loading="loading" border :data="dataList">
        <el-table-column width="50" label="ID" prop="outLinkId" />
        <el-table-column
          label="链接名称"
          prop="siteName"
          align="center"
          :show-overflow-tooltip="true"
        >
          <template slot-scope="scope">
            <el-link @click="handleLink(scope.row.siteUrl)" type="primary">{{
              scope.row.siteName
            }}</el-link>
          </template>
        </el-table-column>
       
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <!-- <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              v-hasPermi="['company:news:info']"
              @click="handleDetail(scope.row.outLinkId)"
              >详情</el-button
            > -->
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['company:news:edit']"
              >修改</el-button
            >
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['company:news:remove']"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
  
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <!-- 添加或修改用户配置对话框 -->
      <el-dialog title="外部链接" :visible.sync="open" width="800px">
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <el-row>
            <el-col :span="24">
              <el-form-item label="链接名称" prop="siteName">
                <el-input v-model="form.siteName" placeholder="请输入链接名称" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="链接地址" prop="siteUrl">
                <el-input v-model="form.siteUrl" placeholder="请输入链接地址" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>
      <detail
        :detailOPen.sync="detailOPen"
        :rowDetail="rowDetail"
        @cancel="cancel"
      ></detail>
    </div>
  </template>
  
  <script>
  import {
    outLinkList,
    outLinkAdd,
    statusChange,
    outLinkEdit,
    outLinkDel,
    outLinkInfo,
    isTopChange,
  } from "@/api/company/outLink.js";
//   import detail from "./detail.vue";
  export default {
    name: "Message",
    dicts: ["sys_normal_disable"],
    components: {
    //   detail,
    },
    data() {
      return {
        dataList: [],
        // 遮罩层
        loading: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        form: {},
        // 表单校验
        rules: {
          siteUrl: [{ required: true, message: "简介不能为空", trigger: "blur" }],
          siteName: [
            { required: true, message: "标题不能为空", trigger: "blur" },
          ],
        //   status: [
        //     { required: false, message: "用户昵称不能为空", trigger: "blur" },
        //   ],
        //   noticeContent: [
        //     { required: true, message: "内容不能为空", trigger: "blur" },
        //   ],
        //   noticeType: [
        //     { required: false, message: "图片不能为空", trigger: "blur" },
        //   ],
        },
        noticeTypeAction: "/base/system/oss/upload",
        noticeTypefileList: [],
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          siteName: undefined,
        //   busType: 1,
        //   ipAddress:this.$VUE_APP_IMG_API
        },
        detailOPen: false,
        rowDetail: {},
      };
    },
    created() {
      this.getList();
      if (this.$route.query.id) {
        this.handleDetail(this.$route.query.id);
      }
      if (this.$route.query.add) {
        this.handleAdd();
      }
    },
    methods: {
      handleDetail(row) {
        this.detailOPen = true;
        outLinkInfo(row).then((res) => {
          this.rowDetail = res.data;
        });
      },
      //是否显示
      handleStatusChange(row) {
        let text = row.status === "1" ? "显示" : "取消显示";
        this.$modal
          .confirm('确认要"' + text + '""' + row.siteName + '"链接吗？')
          .then(function () {
            return statusChange(row.outLinkId, row.status);
          })
          .then(() => {
            this.$modal.msgSuccess(text + "成功");
          })
          .catch(function () {
            row.status = row.status === "0" ? "1" : "0";
          });
      },
      handleIsTop(row) {
        let text = row.isTop === "1" ? "置顶" : "取消置顶";
        this.$modal
          .confirm('确认要"' + text + '""' + row.siteName + '"链接吗？')
          .then(function () {
            return isTopChange(row.outLinkId, row.isTop);
          })
          .then(() => {
            this.$modal.msgSuccess(text + "成功");
            this.getList();
          })
          .catch(function () {
            row.isTop = row.isTop === "0" ? "1" : "0";
          });
      },
      /** 提交按钮 */
      submitForm: function () {
        this.$refs["form"].validate((valid) => {
          if (valid) {
            if (this.form.outLinkId != undefined) {
            outLinkEdit(this.form).then((response) => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              this.form.busType = 1;
              outLinkAdd(this.form).then((response) => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.resetForm("form");
        this.form = JSON.parse(JSON.stringify(row));
        // this.form.status = row.status.toString();
        this.open = true;
        this.title = "修改角色";
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        this.$modal
          .confirm('是否确认删除标题为"' + row.siteName + '"的数据项？')
          .then(function () {
            return outLinkDel(row.outLinkId);
          })
          .then(() => {
            this.getList();
            this.$modal.msgSuccess("删除成功");
          })
          .catch(() => {});
      },
      handleAdd() {
        (this.form = {}), this.resetForm("form");
        this.open = true;
      },
      cancel() {
        this.open = false;
        this.detailOPen = false;
      },
      /** 查询列表 */
      getList() {
        this.loading = true;
        outLinkList(this.queryParams).then((response) => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      handleLink(e){
        window.open(e)
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
    },
  };
  </script>
  <style lang="scss" scoped>
  ::v-deep .el-dialog__body {
    img {
      width: 100%;
    }
  }
  </style>
  